﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace txtTEST
{
    public partial class Form2 : Form
    {

        SimpleControl _simpleControl;//自定义控件
        public Form2()
        {
            InitializeComponent();

            //通过PropertyGrid控件显示自定义控件属性
            _simpleControl = new SimpleControl();
            this.propertyGrid1.SelectedObject = _simpleControl;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }







    }


    class SimpleControl
    {
        int _prop = 1, _prop2 = 3;
        [Browsable(true), Category("布局1"), Description("just a test"), TypeConverter(typeof(genderItem))]
        public int Prop
        {
            get { return _prop; }
            set { this._prop = value; }
        }

        [Browsable(true), Category("布局2"), Description("just a test")]
        public int Prop2
        {
            get { return _prop2; }
            set { this._prop2 = value; }
        }

        public SimpleControl()
        {
            ;
        }



    }

    public class genderItem : Int32Converter
    {
        //true enable,false disable
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return new StandardValuesCollection(new int[] { 1, 2 ,3,4,5,6,7}); //编辑下拉框中的items
        }

        //true: disable text editting.    false: enable text editting;
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
    }

}
